'''
Author: your name
Date: 2020-11-09 14:38:30
LastEditTime: 2020-11-09 16:58:18
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath: \python-study\djangoS\app01\app01\Views\MutilEntity\mutilQuery.py
'''
from django.shortcuts import render, HttpResponse
from django.db.models import Avg, Max, Min, Sum, Count
from Models.models import Emp
from Models.models import Publish1
from Models.models import Book
from django.db.models import F
from django.db.models import Q


class mutilQuery():
    def index(request):
        # res = Book.objects.aggregate(Avg("price"))
        # return HttpResponse(res)
        # res = Publish1.objects.values("name").annotate(in_price = Min("book__price"))
        # 使用F函数查询工资大于年龄的人，通过F函数实现多个字段的比较操作
        # book = Emp.objects.filter(salary__gt=F("age")).values("name", "age")
        # print(type(book), book)
        # return HttpResponse(book)
        # 使用F函数实现表中所有字段的一个批量更新操作
        # res = Book.objects.update(price=F("price")+100)
        # print(res)
        res = Book.objects.filter(Q(pub_date__year=2010) | Q(pub_date__year=1999), title__contains="菜")
        print(res)
        return HttpResponse(res)